<?php

class Login extends Controller {

	function __construct()
	{
		parent::Controller();	
	}
	
	function index()
	{
		$data['page_title'] = "Log in to system";
		$this->load->view('login_view', $data);
	}
	
	function doLogin()
	{
		$this -> load -> model('User_model');
		if(($id = $this -> User_model -> checkLoginData($this -> input -> post('username'), $this -> input -> post('pass'))) === FALSE)
		{
			$this -> session -> set_flashdata('status_message', 'Username or login is wrong.');
			redirect("login");
		}
		// if user is found
		$arr = $this -> User_model -> getUserData($id);
		$this -> session -> set_userdata('user_id', $id);
		$this -> session -> set_userdata('level', $arr['level']);
		redirect("core");
	}
	
	function doLogout()
	{
		$this -> session -> sess_destroy();
		redirect("login");
	}
}